<?php


namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\model\PlanModel;
use DateInterval;
use DateTime;

class Constant extends BaseController
{

    public static function getFileDir(){
        return dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/public/files';
    }

    public function getConstants(){

        $cur_month = date('Ym');
        $max_month = PlanModel::max('month');
        $max_issue = DateTime::createFromFormat('Ym', $max_month);
        $max_issue->add(new DateInterval('P1M'));

        $next_month = $max_issue->format('Ym');
        $is_copy = true;
        if (($next_month - $cur_month) > 2) {
            $is_copy = false;
        }

        return [
            'max_month' => $max_month,
            'is_copy' => $is_copy,
            'help_url' => config('const.help_url'),
            'copy_url' => config('const.copy_url'),
            'ym' => date('Ym', time())
        ];
    }
}